package org.directfire.player.utils;

import java.util.List;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
/**
 *   Copyright (C) 2012 Alexey Kostrjitskiy mailto:alex@ipss.net
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * $Id: DFPagerAdapter.java 5 2012-08-24 20:45:43Z alexeyvk@gmail.com $<br/>
 * $HeadURL: http://directfire.googlecode.com/svn/branches/0.1/DirectFireAndroid/src/org/directfire/player/utils/DFPagerAdapter.java $<br/><br/>
 *
 * DirectFirePlayer ViewPager adapter for ApplicationActivity. */
public class DFPagerAdapter extends PagerAdapter {
	public static final int VIEW0_PLAYER = 0;
	public static final int VIEW1_SCHEDULE = 1;
	public static final int VIEW2_NEWS = 2;
	
	/** list of the tabs*/
	private List<View> pages = null;
  
	/** public constructor */
  public DFPagerAdapter(List<View> pages){
      this.pages = pages;
  }

  /** @param v - tab to remove */
  public void removePage(View v){
  	if(pages.contains(v))
  	{
  		pages.remove(v);
  		notifyDataSetChanged();
  	}
  }
  
  /** @param v - tab to add */
  public void addPage(View v){
  	if(!pages.contains(v)){
  		pages.add(v);
  		notifyDataSetChanged();
  	}
  }
  
  @Override
  public Object instantiateItem(View collection, int position){
  	View v = pages.get(position);
    ((ViewPager) collection).addView(v, 0);
    return v;
  }
  
  @Override
  public void destroyItem(View collection, int position, Object view){
  	((ViewPager) collection).removeView((View) view);
  }
  
  @Override
  public int getCount(){
  	return pages.size();
  }
  
  @Override
  public boolean isViewFromObject(View view, Object object){
  	return view.equals(object);
  }

  @Override
  public void finishUpdate(View arg0){
  }

  @Override
  public void restoreState(Parcelable arg0, ClassLoader arg1){
  }

  @Override
  public Parcelable saveState(){
  	return null;
  }

  @Override
  public void startUpdate(View arg0){
  }
  
  /** @return page title from view Tag */
  public CharSequence getPageTitle(int pPosition) {
  	return (String) (pages.get(pPosition).getTag());
  }
}
